
Research
Security News
Malicious PyPI Package Exploits Deezer API for Coordinated Music Piracy
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
The keycode npm package is a utility for converting between keyboard key codes and their corresponding key names. It simplifies the process of handling keyboard events by providing easy-to-use functions for key code and key name conversions.
Convert Key Code to Key Name
This feature allows you to convert a key code to its corresponding key name. For example, the key code 13 corresponds to the 'Enter' key.
const keycode = require('keycode');
const keyName = keycode(13); // 'enter'
console.log(keyName);
Convert Key Name to Key Code
This feature allows you to convert a key name to its corresponding key code. For example, the key name 'enter' corresponds to the key code 13.
const keycode = require('keycode');
const keyCode = keycode('enter'); // 13
console.log(keyCode);
Handle Keyboard Events
This feature allows you to handle keyboard events by converting the event object to a key name. This can be useful for logging or handling specific key presses in your application.
const keycode = require('keycode');
document.addEventListener('keydown', (event) => {
const keyName = keycode(event);
console.log(`Key pressed: ${keyName}`);
});
The keycode-js package provides a similar functionality to keycode by offering a set of constants for key codes and functions to convert between key codes and key names. It is more focused on providing a comprehensive list of key codes as constants.
Mousetrap is a library for handling keyboard shortcuts in JavaScript. While it offers more advanced features for binding and handling keyboard shortcuts, it also includes functionality for converting key codes to key names and vice versa. It is more feature-rich compared to keycode.
Hotkeys-js is a library for handling keyboard shortcuts in JavaScript. It provides a simple API for binding and unbinding keyboard shortcuts and includes functionality for key code and key name conversions. It is similar to keycode but with additional features for managing keyboard shortcuts.
Simple map of keyboard codes.
$ npm install keycode
$ component install timoxley/keycode
var keycode = require('keycode');
document.addEventListener('keydown', function(e) {
console.log("You pressed", keycode(e))
})
keycode
tries to make an intelligent guess as to what
you're trying to discover based on the type of argument
you supply.
Returns the name of the key associated with this event.
document.body.addEventListener('keyup', function(e) {
console.log(keycode(e)) // prints name of key
})
Due to the keypress event being weird,keycode
currently does not support the keypress
event, but this should not be an issue as keydown
and keyup
work perfectly fine.
Returns the lowercase name of a given numeric keycode.
keycode(13) // => 'enter'
Returns the numeric keycode for given key name.
keycode('Enter') // => 13
// keycode is not case sensitive
keycode('eNtEr') // => 13
Common aliases are also supplied:
> for (var alias in keycode.aliases) { console.log(alias, keycode(keycode(alias))) }
ctl ctrl
pause pause/break
break pause/break
caps caps lock
escape esc
pgup page up
pgdn page down
ins insert
del delete
spc space
Tests if an keyboard event against a given name or keycode.
Will return true
if the event matches the given name or keycode, false
otherwise.
// assume event is an keydown event with key 'enter'
keycode.isEventKey(event, 'enter') // => true
keycode.isEventKey(event, 'down') // => false
keycode.isEventKey(event, 13) // => true
keycode.isEventKey(event, 40) // => false
Key code/name maps are available directly as keycode.codes
and keycode.names
respectively.
keycode.names[13] // => 'enter'
keycode.codes['enter'] // => 13
project : keycode
repo age : 3 years, 8 months
active : 29 days
commits : 66
files : 13
authors :
49 Tim Oxley 74.3%
4 jkroso 6.1%
3 Amir Abu Shareb 4.5%
1 Greg Reimer 1.5%
1 Kenan Yildirim 1.5%
1 Abel Toledano 1.5%
1 Sam 1.5%
1 TJ Holowaychuk 1.5%
1 Yoshua Wuyts 1.5%
1 Nathan Zadoks 1.5%
1 Brenton Simpson 1.5%
1 Brian Noguchi 1.5%
1 Gilad Peleg 1.5%
Original key mappings lifted from http://jsfiddle.net/vWx8V/ via http://stackoverflow.com/questions/5603195/full-list-of-javascript-keycodes
FAQs
Convert between keyboard keycodes and keynames and vice versa.
The npm package keycode receives a total of 615,198 weekly downloads. As such, keycode popularity was classified as popular.
We found that keycode demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
Research
The Socket Research Team discovered a malicious npm package, '@ton-wallet/create', stealing cryptocurrency wallet keys from developers and users in the TON ecosystem.
Security News
Newly introduced telemetry in devenv 1.4 sparked a backlash over privacy concerns, leading to the removal of its AI-powered feature after strong community pushback.